package com.duyutian.controller.hiwodytController.service.impl;

import com.duyutian.controller.hiwodytController.service.LogService;
import com.duyutian.model.LogInfo;
import com.duyutian.util.RedisTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by dyt on 2018/10/17.
 */
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private RedisTools redisTools;

    @Override
    public void setLog(String ip) {

        //每一次访问都算访问量
            List<LogInfo> loger = LogInfo.dao.find("select * from log_info where ip = ? ", ip);
            if (loger.size() == 0 || loger == null) {
                LogInfo logInfo = new LogInfo();
                logInfo.setIp(ip);
                logInfo.setCreated(new Date());
                logInfo.setLogged(new Date());
                logInfo.setNumber(1);
                logInfo.save();
            } else {
                LogInfo logInfo = loger.get(0);
                logInfo.setLogged(new Date());
                logInfo.setNumber(logInfo.getNumber() + 1);
                logInfo.update();
            }
            //向redis中初始化该访客

            //判断是否已经有该访客


    }
}
